package com.lovo.frame;

import com.lovo.pojo.UserDO;
import com.lovo.util.Util;
import com.lovo.util.DBUtil;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MenuPanel extends JPanel implements ActionListener {
    private ATM frame;
    private JButton searchBtn = new JButton(Util.getIcon("/images/buttonFind.jpg"));
    private JButton saveBtn = new JButton(Util.getIcon("/images/buttonSave.jpg"));
    private JButton getBtn = new JButton(Util.getIcon("/images/buttonGet.jpg"));
    private JButton transferBtn = new JButton("转账");
    private JButton changePwdBtn = new JButton(Util.getIcon("/images/buttonModify.jpg"));
    private JButton exitBtn = new JButton(Util.getIcon("/images/buttonOff.jpg"));
    public MenuPanel(ATM frame){
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        searchBtn.setBounds(0,100,140,50);
        searchBtn.addActionListener(this);
        this.add(searchBtn);

        saveBtn.setBounds(900,100,140,50);
        saveBtn.addActionListener(this);
        this.add(saveBtn);

        getBtn.setBounds(0,250,140,50);
        getBtn.addActionListener(this);
        this.add(getBtn);

        transferBtn.setBounds(900,250,140,50);
        transferBtn.addActionListener(this);
        this.add(transferBtn);

        changePwdBtn.setBounds(0,400,140,50);
        changePwdBtn.addActionListener(this);
        this.add(changePwdBtn);

        exitBtn.setBounds(900,400,140,50);
        exitBtn.addActionListener(this);
        this.add(exitBtn);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == searchBtn){
            DBUtil db = new DBUtil();
            UserDO user = db.getById(frame.getLoginUser().getId());
            frame.getSearchPanel().setBlance(user.getBlance());

            frame.switchPanel("search");
        }else if(e.getSource() == saveBtn){

        }else if(e.getSource() == getBtn){
            frame.switchPanel("get");
        }else if(e.getSource() == transferBtn){
            frame.switchPanel("transfer");
        }else if(e.getSource() == exitBtn){
            frame.switchPanel("login");
        }
    }
}
